/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights
 * reserved. <a>http://www.cqcis.com</a>
 */
package com.cqcis.uip.base.framework.core.cluster;

import com.cqcis.uip.base.framework.utils.StringUtil;

/**
 * 集群节点定义
 * 
 * @author huangmy
 * @date 2009-1-5
 */
public class ClusterNode {
	private String name; // 节点名称
	private String host; // 主机地址
	private int port; // 端口
	private String username; // 用户名
	private String password; // 密码
	
	public ClusterNode(String name, String host, int port, String username, String password) {
		if (!StringUtil.hasText(name)
				|| !StringUtil.hasText(host)
				|| !StringUtil.hasText(username)
				|| !StringUtil.hasText(password)
				|| port <= 0
				) {
			throw new IllegalArgumentException("Illegal Arguments");
		}
		
		checkText(name);
		checkText(host);
		checkText(username);
		checkText(password);
		
		this.name = name;
		this.host = host;
		this.port = port;
		this.username = username;
		this.password = password;
	}
	
	private void checkText(String text) {
		if (text.indexOf("(") >= 0 
				|| text.indexOf(")") >= 0
				|| text.indexOf(":") >= 0
				|| text.indexOf("@") >= 0
				|| text.indexOf("-") >= 0) {
			throw new IllegalArgumentException("Can't with '(' ')' ':' '@' '-', param: " + text);
		}
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getHost() {
		return host;
	}

	public void setHost(String host) {
		this.host = host;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
}
